package com.taobao.modules.mina.sendobject;

import java.net.InetSocketAddress;

import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder;
import org.apache.mina.core.future.ConnectFuture;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory;
import org.apache.mina.transport.socket.nio.NioSocketConnector;

public class MinaClient {
	private static MinaClient mainClient = null;


	public static MinaClient getInstances() {
		if (null == mainClient) {
			mainClient = new MinaClient();
		}
		return mainClient;
	}

	private MinaClient() {
		NioSocketConnector connector = new NioSocketConnector();
		DefaultIoFilterChainBuilder chain = connector.getFilterChain();
		chain.addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
		connector.setHandler(ClientHandler.getInstances());
		ConnectFuture cf = connector.connect(new InetSocketAddress("10.13.104.19", 8888));
		cf.awaitUninterruptibly();
	}

	public static void main(String args[]) {
		MinaClient.getInstances();
	}
}
